package com.kingsoft.miot.bridge.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.kingsoft.miot.bridge.controller.req.OrderBy;
import com.kingsoft.miot.bridge.controller.resp.PageResult;
import com.kingsoft.miot.bridge.dao.HotelInfoDao;
import com.kingsoft.miot.bridge.dao.RoomInfoDao;
import com.kingsoft.miot.bridge.exception.CommonException;
import com.kingsoft.miot.bridge.pojo.hotel.RoomInfo;
import com.kingsoft.miot.bridge.service.RoomService;

/**
 * 房间信息服务
 * 
 * @author HUJIANQING
 *
 */
@Service
public class RoomServiceImpl implements RoomService {

	private static final Logger LOGGER = LoggerFactory.getLogger(RoomServiceImpl.class);

	@Autowired
	private RoomInfoDao roomInfoDao;

	@Autowired
	private HotelInfoDao hotelInfoDao;

	/**
	 * 新增
	 */
	@Transactional(propagation = Propagation.SUPPORTS)
	@Override
	public void insertOne(RoomInfo roomInfo) {
		try {
			roomInfoDao.insertOne(roomInfo);
		} catch (Exception e) {
			LOGGER.error("新增房间失败。");
			throw new CommonException(e);
		}
	}

	/**
	 * 通过room id 获取room info
	 */
	@Transactional(propagation = Propagation.SUPPORTS)
	@Override
	public RoomInfo getByRoomInfoId(int room_info_id) {
		RoomInfo roomInfo = null;
		try {
			roomInfo = roomInfoDao.getByRoomInfoId(room_info_id);
		} catch (Exception e) {
			LOGGER.error("获取房间失败。");
			throw new CommonException(e);
		}
		return roomInfo;
	}

	/**
	 * 通过 hotle id 获取room info
	 */
	@Transactional(propagation = Propagation.SUPPORTS)
	@Override
	public List<RoomInfo> getByHotelInfoId(int hotel_info_id) {
		List<RoomInfo> roomInfoList = null;
		try {
			roomInfoList = roomInfoDao.getByHotelInfoId(hotel_info_id);
		} catch (Exception e) {
			LOGGER.error("获取房间失败。");
			throw new CommonException(e);
		}
		return roomInfoList;
	}

	/**
	 * 获得所有
	 */
	@Override
	public List<RoomInfo> findAll() {
		List<RoomInfo> roomInfoList = null;
		try {
			roomInfoList = roomInfoDao.findAll();
		} catch (Exception e) {
			LOGGER.error("获取房间失败。");
			throw new CommonException(e);
		}
		return roomInfoList;
	}

	/**
	 * 通过hotel id 查询相关的房间  并分页
	 */
	@Override
	public PageResult<RoomInfo> findHotelRoomByPage(int hotel_info_id, int currentPage, int pageSize,
			List<OrderBy> orderByList) {
		
		return null;
	}

}
